"use strict";

let nunjucks = require('nunjucks');

function createConfig(){
    let path = 'views';

    let envconfig ={
        autoescape : true,
        throwOnUndefined : false,
        trimBlocks : false,
        lstripBlocks : false,
        watch : true,
        noCache : true
    }

    let env = nunjucks.configure(path,envconfig);

    return env;
}

module.exports = async (ctx,next)=>{
    let env = createConfig();

    ctx.render = function(views,model){
        ctx.body = env.render(views,model);
    }

    await next();
}